var mysql      = require('mysql');

// 创建链接
var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : 'root',
  database : 'my_db'
});
 
// 链接数据库 打开冰箱门
connection.connect();
 
// 执行数据库操作，把大象放到冰箱
connection.query('select * from users', function (error, results, fields) {
  if (error) throw error;
  console.log('The solution is: ', results[0].solution);
});

connection.query('insert into users values(null,"admin","123456")', function (error, results, fields) {
    if (error) throw error;
    console.log('The solution is: ', results[0].solution);
  });
 
// 关闭链接 关闭冰箱门
connection.end();